const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const User = sequelize.define('User', {
  id: { 
    type: DataTypes.INTEGER.UNSIGNED, 
    primaryKey: true, 
    autoIncrement: true,
    comment: '主键'
  },
  nickName: { 
    type: DataTypes.STRING(50), 
    allowNull: false, 
    field: 'nick_name',
    comment: '用户昵称'
  },
  avatarUrl: { 
    type: DataTypes.STRING(255), 
    allowNull: true, 
    field: 'avatar_url',
    comment: '头像URL'
  },
  openid: { 
    type: DataTypes.STRING(128), 
    allowNull: true, 
    unique: true, 
    field: 'openid',
    comment: '微信用户唯一标识'
  },
  active: { 
    type: DataTypes.TINYINT, 
    allowNull: false, 
    defaultValue: 1, 
    field: 'is_active',
    comment: '状态：1启用 0禁用'
  }
}, {
  tableName: 'users',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  comment: '用户表'
});

module.exports = User;